package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.UserRoleFrom;
import com.moss.cloud.base.biz.service.ISysUserRoleService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ServiceList.BASE + "/sysUserRole")
public class SysUserRoleController {
    private ISysUserRoleService sysUserRoleService;
    public SysUserRoleController(ISysUserRoleService sysUserRoleService){
        this.sysUserRoleService = sysUserRoleService;
    }
    /**
     * 用户ID查询角色信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/roleInfoByUserId")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "用户ID查询角色信息")
    public Result<?> roleInfoByUserId(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysUserRoleService.roleInfoByUserId(baseFrom.getId()));
    }

    /**
     * 批量保存用户角色
     *
     * @param userRoleFrom
     * @return
     */
    @PostMapping("/saveBatchUserRole")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "用户角色授权")
    public Result<?> saveBatchUserRole(@RequestBody @Validated UserRoleFrom userRoleFrom){
        return Result.success(sysUserRoleService.saveBatchUserRole(userRoleFrom));
    }
}
